package genome;


import static org.junit.Assert.*;

import java.util.ArrayList;

import org.junit.*;

import tool.Utility;

public class CGPTest {

	private CGP g1;
	private CGP g2;
	private double[] default_input = {0.0};
	private int[] sample_genome1 = {0,0,0,1,1,1};
	private int[] sample_genome2 = {0,0,1,0,1,0};
	private int default_size = 6;
	
	@Before
	public void setUp() throws Exception {
		g1 = new CGP(default_input,default_size);
		g2 = new CGP(default_input,default_size);
		g1.genome=sample_genome1;
		g2.genome=sample_genome2;
		

	}
	
	@Test
	public void sampleSpaceTest(){
		ArrayList<Genotype> space = g1.generateSpace(10);
		assertTrue(space.size()==10);
	}
	
	@Test
	public void differenceTest(){
		double diff1 = g1.diff(g2);
		double diff2 = g2.diff(g1);
		assertTrue(diff1==diff2);
	}
	
	@Test
	public void distanceTest(){
		double d1 = g1.distanceTo(g2);
		double d2 = g2.distanceTo(g1);
		assertTrue(d1==d2);
		
		//Check against manually calculated values for 0.1 mutation rate and the default genomes
		double pSame = 0.95*0.95*(0.9+0.1/3)*(0.9+0.1/CGP.NUM_FUNCTIONS);
		double pDiff = (0.1/CGP.NUM_FUNCTIONS)*(0.1/3);
		
		double expectedProbability = Utility.roundToSignificantFigures(pSame*pDiff, 5);
		
		assertTrue(d1==expectedProbability);
		
	}
	
	@Test
	public void testFitSymbolicRegression(){
		double[] range = {0.0,2.0};
		double f=g2.quickSymbolicRegression(4,range);
		System.out.println(g2+" "+g2.toMathString()+" "+f);
	}

}
